﻿using HandyControl.Tools;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Shell;

namespace Tnelab.Wpf
{
	public partial class WindowEx
	{
		private static WindowChrome _chrome = new() {
			CornerRadius = new(10),
			CaptionHeight = 0,
			GlassFrameThickness = new(1),
			UseAeroCaptionButtons = false,
			NonClientFrameEdges = NonClientFrameEdges.None
		};
		public static readonly DependencyProperty WindowChromeableProperty =
			DependencyProperty.RegisterAttached("WindowChromeable", typeof(bool), typeof(WindowEx), new(false, OnWindowChromeableChanged));
		private static void OnWindowChromeableChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
		{
			if (DesignerHelper.IsInDesignMode)
				return;
			var window = obj as Window;
			if (e.NewValue != e.OldValue)
			{
				var value = (bool)e.NewValue;
				if (value)
				{
					WindowChrome.SetWindowChrome(window, _chrome);
				}
				else
				{
					WindowChrome.SetWindowChrome(window, null);
				}
			}
		}

		public static bool GetWindowChromeable(Window dpo)
		{
			return (bool)dpo.GetValue(WindowChromeableProperty);
		}

		public static void SetWindowChromeable(Window dpo, bool value)
		{
			dpo.SetValue(WindowChromeableProperty, value);
		}
	}
}
